package edu.washington.cs.workflow.analysis.guistructure;

import edu.washington.cs.workflow.instrument.InstruPointsController;
import edu.washington.cs.workflow.instrument.InstrumentStats;
import junit.framework.TestCase;

public class TestInstrumentUIActionTracer extends TestCase {

	public void testInstrumentCalAddressBook() throws Exception {
		String inputJar = "./experiments/calculatorAndAddressbook.jar";
		String outputJar = "./experiments/calculatorAndAddressbook-instr.jar";
		this.instrument(inputJar, outputJar);
	}
	
	public void testInstrumentCrossword030() throws Exception {
		String inputJar = "./experiments/crossword-0.3.jar";
		String outputJar = "./experiments/crossword-0.3-instr.jar";
		this.instrument(inputJar, outputJar);
	}
	
	public void testInstrumentCrossword035() throws Exception {
		String inputJar = "./experiments/crossword-0.3.5.jar";
		String outputJar = "./experiments/crossword-0.3.5-instr.jar";
		this.instrument(inputJar, outputJar);
	}
	
	public void testInstrumentJEdit25() throws Exception {
		String inputJar = "./experiments/jedit-2.5.jar";
		String outputJar = "./experiments/jedit-2.5-instr.jar";
		this.instrument(inputJar, outputJar, new String[]{"org.gjt.sp.jedit"});
	}
	
	public void testInstrumentJEdit26() throws Exception {
		String inputJar = "./experiments/jedit-2.6.jar";
		String outputJar = "./experiments/jedit-2.6-instr.jar";
		this.instrument(inputJar, outputJar, new String[]{"org.gjt.sp.jedit"});
	}
	
	public void testInstrumentJabRef20() throws Exception {
		String inputJar = "./experiments/jabref2.0/jabref-2.0.jar";
		String outputJar = "./experiments/jabref2.0/jabref-2.0-instr.jar";
		this.instrument(inputJar, outputJar, new String[]{"net.sf.jabref"});
	}
	
	public void testInstrumentJabRef281() throws Exception {
		String inputJar = "./experiments/jabref2.8/JabRef-2.8.1.jar";
		String outputJar = "./experiments/jabref2.8/JabRef-2.8.1-instr.jar";
		this.instrument(inputJar, outputJar, new String[]{"net.sf.jabref"});
	}
	
	public void testInstrumentFreemind080() throws Exception {
		String inputJar = "./original-jars/freemind-0.8.jar";
		String outputJar = "./experiments/freemind-0.8/freemind-0.8-instr.jar";
		this.instrument(inputJar, outputJar, new String[]{"freemind"});
	}
	
	public void testInstrumentFreemind071() throws Exception {
		String inputJar = "./experiments/freemind-0.71/freemind-0.71.jar";
		String outputJar = "./experiments/freemind-0.71/freemind-0.71-instr.jar";
		this.instrument(inputJar, outputJar, new String[]{"freemind."});
	}
	
	//package names: org\ganttproject\
	//net.sourceforge.ganttproject
	public void testInstrumentGanttProject254() throws Exception {
		String[] pkgs = new String[]{"org.ganttproject", "net.sourceforge.ganttproject"};
		
		String inputJar1 = "./experiments/gantt2.5.4/eclipsito.jar";
		String outputJar1 = "./experiments/gantt2.5.4-instr/eclipsito.jar";
		this.instrument(inputJar1, outputJar1, pkgs);
		
		String inputJar2 = "./experiments/gantt2.5.4/plugins/biz.ganttproject.impex.msproject2/ganttproject-msproject2.jar";
		String outputJar2 = "./experiments/gantt2.5.4-instr/plugins/biz.ganttproject.impex.msproject2/ganttproject-msproject2.jar";
		this.instrument(inputJar2, outputJar2, pkgs);
		
		String inputJar3 = "./experiments/gantt2.5.4/plugins/net.sourceforge.ganttproject/ganttproject.jar";
		String outputJar3 = "./experiments/gantt2.5.4-instr/plugins/net.sourceforge.ganttproject/ganttproject.jar";
		this.instrument(inputJar3, outputJar3, pkgs);
		
		String inputJar4 = "./experiments/gantt2.5.4/plugins/org.ganttproject.chart.pert/pert.jar";
		String outputJar4 = "./experiments/gantt2.5.4-instr/plugins/org.ganttproject.chart.pert/pert.jar";
		this.instrument(inputJar4, outputJar4, pkgs);
		
		String inputJar5 = "./experiments/gantt2.5.4/plugins/org.ganttproject.impex.htmlpdf/ganttproject-htmlpdf.jar";
		String outputJar5 = "./experiments/gantt2.5.4-instr/plugins/org.ganttproject.impex.htmlpdf/ganttproject-htmlpdf.jar";
		this.instrument(inputJar5, outputJar5, pkgs);
	}
	
    public void testInstrumentGanttProject20() throws Exception {
        String[] pkgs = new String[]{"org.ganttproject", "net.sourceforge.ganttproject"};
		
		String inputJar1 = "./experiments/gantt2.0/eclipsito.jar";
		String outputJar1 = "./experiments/gantt2.0-instr/eclipsito.jar";
		this.instrument(inputJar1, outputJar1, pkgs);
		
		String inputJar2 = "./experiments/gantt2.0/plugins/net.sourceforge.ganttproject_2.0.0/ganttproject.jar";
		String outputJar2 = "./experiments/gantt2.0-instr/plugins/net.sourceforge.ganttproject_2.0.0/ganttproject.jar";
		this.instrument(inputJar2, outputJar2, pkgs);
		
		String inputJar3 = "./experiments/gantt2.0/plugins/org.ganttproject.chart.pert_2.0.0/pert.jar";
		String outputJar3 = "./experiments/gantt2.0-instr/plugins/org.ganttproject.chart.pert_2.0.0/pert.jar";
		this.instrument(inputJar3, outputJar3, pkgs);
		
		String inputJar4 = "./experiments/gantt2.0/plugins/org.ganttproject.impex.htmlpdf_2.0.0/ganttproject-htmlpdf.jar";
		String outputJar4 = "./experiments/gantt2.0-instr/plugins/org.ganttproject.impex.htmlpdf_2.0.0/ganttproject-htmlpdf.jar";
		this.instrument(inputJar4, outputJar4, pkgs);
		
		String inputJar5 = "./experiments/gantt2.0/plugins/org.ganttproject.impex.msproject_2.0.0/ganttproject-msproject.jar";
		String outputJar5 = "./experiments/gantt2.0-instr/plugins/org.ganttproject.impex.msproject_2.0.0/ganttproject-msproject.jar";
		this.instrument(inputJar5, outputJar5, pkgs);
	}
	
	void instrument(String inputJar, String outputJar) throws Exception {
		instrument(inputJar, outputJar, null);
	}
	
	void instrument(String inputJar, String outputJar, String[] appPackages) throws Exception {
//		String[] appPackages = null; //new String[]{"crosswordsage"};
        InstruPointsController controller = new InstruPointsController(appPackages);
		UIActionTraceInstrumenter instrumenter = new UIActionTraceInstrumenter(controller);
		instrumenter.instrument(inputJar, outputJar);
		InstrumentStats.showInstrumentationStats();
	}
}
